<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../header.jsp"%>
<script type="text/javascript">

var detailValidator;

function selectMenu() {
	$.openDialog("#dialog",
			{height:450,
			width:330,
			loadPage:"/biz/system/menu/query.jsp",
			title:"选择上级菜单"},
			function(data) {
				$("#menuParent").data("id",data.data("id"));
				$("#menuParent").val(data.data("name"));
			});
}

function saveDetail() {
	if (!detailValidator.form()) {
		return;
	}
	doSaveDetail();
}

function doSaveDetail() {
	var data = {
			id : $("#menuId").val(),
			name : $("#menuName").val(),
			code : $("#menuCode").val(),
			parentId: $("#menuParent").data("id"),
			url : $("#menuUrl").val(),
			description : $("#menuDesc").val()
		};
	
	$.ajax({
		type: "POST",
		url: "save.json",
		data: data,
		dataType: "json",
		success: saveSucceedCallback,
		error:function(message){
			$.alert(message);
		}  
	});
}

function saveSucceedCallback(data) {
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}

	$("#menuId").val(data.data.id);
	$.info("保存成功！");
}

$(document).ready(function() {
	$("#menuParent").data("id",$("#menuParentId").val());

	detailValidator = $("#detailForm").validate({
		rules: {
			menuName:{required:true},
			menuCode:{required:true},
			menuUrl:{required:true}
		},
		messages:{
			menuName:{required:"请输入名称"},
			menuCode:{required:"请输入编码"},
			menuUrl:{required:"请输入Url地址"}
		}
	});

});

</script>

<div class="border bg">

<div class="page-header">
<h2>菜单<small> - ${(data.name==null)?"新增":data.name}</small></h2>
<div class="cms_toolbar"><a href="./" class="btn"><i class="icon-list"></i>返回</a></div>
</div>

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="menuId" value="${data.id}">
<input type="hidden" id="menuParentId" value="${data.parentId}">

<fieldset>
	<div class="control-group">
		<label for="menuName" class="control-label">名称：</label>
		<div class="controls">
			<input type="text" id="menuName" name="menuName" value="${data.name}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="menuCode" class="control-label">编码：</label>
		<div class="controls">
			<input type="text" id="menuCode" name="menuCode" value='${data.code}'> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="menuUrl" class="control-label">URL：</label>
		<div class="controls">
			<input type="text" id="menuUrl" name="menuUrl" value="${data.url}"> <span class="cms_color_required">*</span> 
		</div>
	</div>
	<div class="control-group">
		<label for="menuParent" class="control-label">上级菜单：</label>
		<div class="controls">
			<input type="text" id="menuParent" readonly="readonly" name="menuParent" value="${data.parentName}"><input type="button" class="btn" value="选择" onclick="selectMenu()">
		</div>
	</div>
	<div class="control-group">
		<label for="menuDesc" class="control-label">描述：</label>
		<div class="controls">
			<textarea id="menuDesc" name="menuDesc">${data.description}</textarea>
		</div>
	</div>
	<div class="form-actions">
			<a href="javascript:;" class="btn btn-primary" onclick="saveDetail()"><i class="icon-ok"></i>保存</a>
			<a href="edit.do" class="btn btn-info" ><i class="icon-plus"></i>继续添加</a>
	</div>
</fieldset>

</form> 

</div>

<%@ include file="../../../footer.jsp"%>